//
// Created by Huafv on 2024/10/16.
//

#ifndef BT_COMMON_H
#define BT_COMMON_H


#include <stdint.h>
#include "bt_hci.h"
#include "bt_config.h"

#ifndef err_t
typedef int8_t err_t;
#endif

typedef enum {
/** No error, everything OK. */
    BT_ERR_OK         = 0,
/** Out of memory error.     */
    BT_ERR_MEM        = -1,

/** Illegal value.           */
    BT_ERR_VAL        = -6,
/** Connection closed.       */
    BT_ERR_CLSD       = -15,
/** Illegal argument.        */
    BT_ERR_ARG        = -16,
} bt_err_enum_t;


#define MEM_ALIGNMENT 4
#define MEM_ALIGN_SIZE(size) (((size) + MEM_ALIGNMENT - 1) & ~(MEM_ALIGNMENT-1))


#define bt_htons(x) ((((x) & 0x00ffUL) << 8) | (((x) & 0xff00UL) >> 8))
#define bt_ntohs(x) ((((x) & 0x00ffUL) << 8) | (((x) & 0xff00UL) >> 8))
#define bt_htonl(x) ((((x) & 0x000000ffUL) << 24) | \
                     (((x) & 0x0000ff00UL) <<  8) | \
                     (((x) & 0x00ff0000UL) >>  8) | \
                     (((x) & 0xff000000UL) >> 24))
#define bt_ntohl(x) ((((x) & 0x000000ffUL) << 24) | \
                     (((x) & 0x0000ff00UL) <<  8) | \
                     (((x) & 0x00ff0000UL) >>  8) | \
                     (((x) & 0xff000000UL) >> 24))

#define bt_htonll(x) ((((uint64_t)bt_htonl(x)) << 32) + bt_htonl((x) >> 32))


#endif //BT_COMMON_H
